package cn.levill.domain.strategy.model.entity;

import cn.levill.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * @author Levill
 * @description 策略实体
 * @date 2025/01/18 16:49
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyEntity {
    /**
     * 抽奖策略ID
     */
    private Long strategyId;
    /**
     * 抽奖策略描述
     */
    private String strategyDesc;
    /**
     * 抽奖模型
     */
    private String ruleModels;


    /**
     * 判断ruleModels是否有配置规则 有将其返回存入数组
     *
     * @return {@link String[] }
     */
    public String[] ruleModels(){
        if (StringUtils.isBlank(ruleModels)) return null;
        return ruleModels.split(Constants.SPLIT);
    }

    /**
     * 获取到权重规则
     *
     * @return {@link String }
     */
    public String getRuleWeight(){
        String[] ruleModels = this.ruleModels();
        if (null == ruleModels) return null;
        for (String ruleModel : ruleModels) {
            if ("rule_weight".equals(ruleModel)) return ruleModel;
        }
        return null;
    }
}
